package com.tys.algorithm.bak.test;

public class Code07_Swap {
    public static void main(String[] args) {
        int a = 16;
        int b = 603;
        System.out.println(a + " " + b);
        a = a ^ b;
        b = a ^ b;
        a = a ^ b;
        System.out.println(a + " " + b);


        System.out.println("=====================");
        //注意数组中如果相同下标则会出错
        int[] arr = {3, 15, 100};
        int i = 0;
        int j = 0;
//        arr[i] = arr[i] ^ arr[j];
//        arr[j] = arr[i] ^ arr[j];
//        arr[i] = arr[i] ^ arr[j];
//        System.out.println(arr[i] + ", " + arr[j]);

        System.out.println(arr[1]);
        swap(arr, 1, 1);
        System.out.println(arr[1]);

    }

    public static void swap(int[] arr, int i, int j) {
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }
}
